/*-
 * Copyright (c) 2006, 2007 FTS Team
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 4. Neither the name of the FTS Team nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *      MemoryDocumentInfoStorage.cpp
 *
 * $FTS$
 */
#ifndef _MEMORY_DOCUMENT_INFO_STORAGE_HPP__
#define _MEMORY_DOCUMENT_INFO_STORAGE_HPP__ 1

/**
  @file DocumentInfo.hpp
  @brief Generic information about stored document
*/
#include <DocumentInfoStorage.hpp>
#include <DataDumper.hpp>
#include <Hash.hpp>
#include <HashFunctions.hpp>
#include <FileDocumentStorage.hpp>

#define C_MEM_DB_READABLE "Document properties memory data dump (uncompressed)"
#define C_MEM_DB_TYPE     0x00000003

namespace FTSS // FullTextSearchSystem
{

/**
  @class MemoryDocumentDataBase MemoryDocumentDataBase.hpp <MemoryDocumentDataBase.hpp>
  @brief Document data base storage
*/
class MemoryDocumentInfoStorage:
  public DocumentInfoStorage
{
public:
	/**
	  @brief Constructor
	*/
	MemoryDocumentInfoStorage();

	/**
	  @brief A Destructor
	*/
	~MemoryDocumentInfoStorage() throw();

	/**
	  @brief Serialize and dump object
	  @return 0 success, -1 - if any error occured
	*/
	INT_32 Dump(DataDumper * pObject);

	/**
	  @brief Restore and de-serialize object
	  @return 0 success, -1 - if any error occured
	*/
	INT_32 Restore(DataDumper * pObject);

	/**
	  @brief Delete and serialize object
	*/
	void DeleteDocument(const DocumentId_t&);

	/**
	 * @brief CompressStorage
	 */
	MemoryDocumentInfoStorage compressInfoStorage(FileDocumentStorage &DocumentSotrage, FileDocumentStorage &DocumentStorage_compressed); 
	
private:
	/**
	  @typedef Pair<DocumentId_t, DocumentInfo> StoragePair
	  @brief Data storage key => value pair type definition
	*/
	typedef Pair<DocumentId_t, DocumentInfo> StoragePair;

	/**
	  @typedef Hash<DocumentId_t, DocumentInfo, HashHasher, HashComparator> StorageHash
	  @brief Data storage type definition
	*/
	typedef Hash<DocumentId_t, DocumentInfo, HashHasher, HashComparator> StorageHash;

	/** Data storage                      */
	StorageHash oStorageHash;
	/** Number of documents in collection */
	Size_t      iDocNum;

	/**
	  @brief A Destructor
	*/
	DocumentInfo * GetInfo(const DocumentId_t & iDocumentId);

	/**
	  @brief Store document information
	*/
	void StoreInfo(const DocumentInfo & oDocumentInfo);
	


};

} // namespace FTSS
#endif // _MEMiRY_DOCUMENT_INFO_STORAGE_HPP_
// End.
